using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace manaTools
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();

            pblc.bolDebug = true;

            //if debugging is true create a debug output form and print appName + Version
            if (pblc.bolDebug == true)
            {
                pblc.frmDebug = new DebugOutForm();
                pblc.frmDebug.Show();
                pblc.frmDebug.writeText("Started " + Application.ProductName + " V" + Application.ProductVersion + "\r\n");
            }
            this.Text = Application.ProductName + " [" + Application.ProductVersion + "] ";
            pblc.mProject = new Project();
            pblc.mMapList = new mapper.CMapList();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AboutForm frmAbout = new AboutForm();
            frmAbout.Show();
        }

        private void openProjectToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlgFileOpen = new OpenFileDialog();
            dlgFileOpen.Title = "Open Project";
            dlgFileOpen.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            dlgFileOpen.Filter = "Textfiles (*.xml)|*.xml";
            //dlgFileOpen.Multiselect false;
            if (dlgFileOpen.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    pblc.frmDebug.writeText(dlgFileOpen.FileName);

                    pblc.mProject.LoadProject(dlgFileOpen.FileName);

                    if (pblc.mMapList.isListLoaded == true)
                    {
                        foreach (CSCL.Games.Manasource.Map tMap in pblc.mMapList.mapList)
                        {
                            this.listBox1.Items.Add(tMap.Name);
                        }
                    }

                    if (pblc.bolDebug == true)
                    {
                        
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Fehler");
                    if (pblc.bolDebug == true)
                    {
                        pblc.frmDebug.writeText("Fehler: " + ex.Message.ToString());
                    }
                }//EndCatch
            }//EndIF
        }

        private void listBox1_SelectedValueChanged(object sender, EventArgs e)
        {
            this.pictureBox1.Load("./" + pblc.mProject.m_Config.m_sClientDataDir
                                    + "graphics/minimaps/"
                                    + this.listBox1.SelectedItem
                                    + ".png");
            this.numericUpDown1.Value = pblc.mMapList.getMapIDFromMapName(this.listBox1.SelectedItem.ToString());
            if (pblc.bolDebug == true)
            {
                pblc.frmDebug.writeText("./" + pblc.mProject.m_Config.m_sClientDataDir
                                        + "graphics/minimaps/"
                                        + this.listBox1.SelectedItem
                                        + ".png");
            }//EndIf
        }
    }
}